import Base from 'models/base';

import moment from 'moment';

export default class GoodsBargainDetail extends Base {
  constructor(goods, systemTime){
    super();

    this.defId = goods.goodsDefId;
    this.name = goods.goodsName;
    this.price = goods.activityPrice;
    this.description = goods.goodsDescription;
    this.tip = goods.goodsTips;

    let pic = goods.goodsPic;
    this.pics = pic.split(',');

    let startTime = moment(goods.activityStartTime).valueOf();
    this.startTime = startTime;

    let endTime = moment(goods.activityEndTime).valueOf();
    this.endTime = endTime;

    this.setGroupType(systemTime);
  }

  setGroupType(nowTime) {
    if (nowTime === undefined) {
      nowTime = moment();
    } else {
      nowTime = moment(nowTime)
    }

    let startTime = this.startTime;
    let endTime = this.endTime;
    let type;
    if (moment(nowTime).isBefore(startTime, 'second')) {
      type = 0;
    } else if (moment(nowTime).isAfter(endTime, 'second')) {
      type = 2;
    } else {
      type = 1;
    }
    this.type = type;
  }
}